package cn.blackhole.simple.domain.level.service.impl;

import cn.blackhole.simple.common.enums.InterfaceType;
import cn.blackhole.simple.domain.level.service.InterfaceTypeDetector;

import java.net.MalformedURLException;
import java.net.URI;

public class DefaultTypeDetector implements InterfaceTypeDetector {

    @Override
    public InterfaceType detect(URI uri) throws MalformedURLException {

        String url = uri.toURL().getPath();

        if (url.contains("/api/v1/")) return InterfaceType.TYPE1;

        if (url.contains("/api/v2/")) return InterfaceType.TYPE2;

        if (url.contains("/api/v3/")) return InterfaceType.TYPE3;

        return InterfaceType.UNKNOWN;
    }
}
